Skip to content

Added Static Mesh Exporter from Pose with GLTF for 3d Printing Meshes#305

Open
benMcChesney wants to merge 15 commits intodonkeyProgramming:masterfrom
benMcChesney:master
Open

Added Static Mesh Exporter from Pose with GLTF for 3d Printing Meshes#305
benMcChesney wants to merge 15 commits intodonkeyProgramming:masterfrom
benMcChesney:master

Conversation

@benMcChesney
Copy link

This PR includes a set of changes to make it easier to export game models for 3d printing. I added a "File > Advanced Export" in the 3d model preview to be able to export specific poses. Originally tried OBJ export but found GLTF higher quality. If the history is too messy happy to clean it up and resubmit.

Exporter and Builder Enhancements:

  • Added RmvToGltfStaticExporterViewModel and RmvToGltfStaticExporter to the dependency injection container, enabling static mesh export functionality.
  • Registered GltfStaticMeshBuilder for static mesh construction, complementing the existing GltfMeshBuilder.

Mesh Building Reliability:

  • Updated GltfMeshBuilder.Build and mesh generation logic to support models with or without skeletons, and to robustly handle meshes with partial or missing weight data. This prevents validation errors during GLTF export. [1] [2] [3]
  • Improved SetVertexInfluences to handle all cases of vertex weight counts (1–4), normalize weights, and provide safe defaults for degenerate or malformed data.

Texture Handling:

  • Added AlphaMaskCombiner, a helper class for combining a diffuse texture and a mask texture into a single RGBA PNG, using the mask as the alpha channel.

Project Structure:

  • Introduced new folders for exporters and presentation layers in the project file to support future expansion and organization.

Export Output Consistency:

  • Changed DdsToNormalPngExporter to output a file named with _raw.png and removed the blue normal map conversion logic for simplification. [1] [2]

Displacement Map Export:

Here's a few FDM prototypes, tested with Warhammer III models
image

able to export to OBJ from a static pose of a rigid_pose_v2 model from TW3
Register and add an Rmv->OBJ exporter and its ViewModel, and update exporter logic and quick-export flow. Changes include: registering RmvToObjExporterViewModel in DI and adding RmvToObjExporterViewModel file; update RmvToObjExporter to use model names for exported normal/diffuse filenames, append a Kd line, and change export helper signatures to accept mesh/model name; enhance normal->height conversion with strength/contrast/blur parameters and a simple separable box blur implementation. Also harden QuickExportPosedMeshCommand: manage original mesh visibility, clone typed mesh nodes, temporarily replace LOD children for saving, handle saveResult and in-memory serialization to create PackFile bytes robustly, and restore scene state in a finally block. These changes improve filename consistency, material output, displacement generation quality, and reliability of quick exports.
Re-encode exported PNGs to high-quality 32bpp and apply mask premultiplication for diffuse textures. Adds System.Drawing.Drawing2D import, EnsurePngHighQuality helper to re-save PNGs with high-quality drawing and 32bpp settings, and PremultiplyDiffuseWithMask to combine an exported mask's luminance into diffuse alpha. Calls to re-encode normals, displacements, diffuse maps and exporter outputs were added (wrapped in try/catch to avoid breaking exports). Logging preserved and failures are ignored to keep exports resilient.
Fixes DDS color channel ordering and restructures texture export flow.

- Correct Pfim BGRA/BGR -> Bitmap ARGB/RGB conversion in TextureHelper and AlphaMaskCombiner to ensure colors/alpha are written correctly.
- DdsToNormalPng: save raw normal PNG and optionally produce a blue normal map variant; return appropriate output path.
- GltfTextureHandler: stop combining diffuse+mask into a single RGBA; export mask as a separate inverted _mask.png, add explicit handling for mask textures, and add export of additional normal map variants (raw and offset).
- Remove displacement map generation: drop IDdsToDisplacementMap registration and displacement generation from exporter and UI (RmvToGltfStaticExporter and ViewModel updated).
- Minor cleanup: explicit System.IO using, fully-qualified ImageFormat usage, small whitespace fixes.
- Remove obsolete Docs/Static_Mesh_Export_Guide.md.

These changes resolve incorrect color channel outputs from Pfim, provide more explicit texture artifacts (raw/blue/offset normal maps and separate masks), and simplify the exporter by removing automatic displacement map generation.
Remove the optional blue normal-map conversion from DdsToNormalPngExporter — it now always saves the raw PNG and the ConvertToBlueNormalMap method and blue-file save path were removed. Add ExportDisplacementMapPng to GltfTextureHandler which reads the existing raw PNG, computes a height/displacement map by converting to luminance, applying iterative smoothing, contrast adjustment and sharpening, normalizes the result, and saves a *_displacement.png alongside the raw and offset outputs.
Generate displacement maps from normal textures and expose quality settings in the static GLTF exporter. Implemented ExportDisplacementFromNormalMap, improved raw/offset normal handling and alpha compositing, and added a displacement processing pipeline (standard, Poisson, multi-scale), contrast/sharpening, bilateral filtering and 8/16-bit export helpers. Added new RmvToGltfExporterSettings fields for displacement control, a new RmvToGltfStaticExporterView XAML + code-behind and updated RmvToGltfStaticExporterViewModel to surface settings and pass them to the exporter. Minor fix in RmvToGltfExporterView XAML whitespace.
Introduce a new ExportDisplacementMaps setting and gate displacement export behind it. When enabled, normal-map variants and displacement maps are generated (standard pipeline, optional 16-bit output, Poisson and multi-scale comparison variants), with contrast, bilateral sharpening and normalization steps. Poisson reconstruction was tuned (fewer iterations, reduced divergence weight) and multi-scale processing now uses the standard height-map backend. When disabled, the code falls back to the regular DDS->PNG normal exporter. Also update the static GLTF exporter ViewModel to rename the display to "GLTF for 3D Printing" and enable ExportDisplacementMaps by default for that workflow. File outputs include _raw.png, _displacement, _displacement_poisson and _displacement_multiscale variants.
When exporting base color textures, export an additional grayscale alpha mask PNG for 3D printing workflows. Adds a call in DoTextureDefault to ExportAlphaMask when settings.ExportDisplacementMaps is enabled and the texture is KnownChannel.BaseColor. Implements ExportAlphaMask to locate the source pack file, decode DDS via Pfim, verify RGBA32 format, extract the alpha channel into a black/white grayscale mask, and save it as <name>_alphamask.png next to the export output. The method includes early returns for missing services/files or unsupported formats.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant